//
//  DBJSAndHPasswordVC.m
//  DBJ
//
//  Created by 肖浩然的mac on 2016/11/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DBJSAndHPasswordVC.h"
#import "UIColor+ZBHAddition.h"
#import "DBJSAndHPasswordView.h"
#import "SSKeychain.h"
#import "DBJUserDefaultsTool.h"
#import <SVProgressHUD.h>
#import "NSString+Regular.h"

@interface DBJSAndHPasswordVC ()

@property (weak, nonatomic) IBOutlet UITextField *oldPaswordTextField;
@property (weak, nonatomic) IBOutlet UITextField *updateTextField;

/** 当前用户帐号 */
@property (nonatomic,weak) NSString *currentAccount;
/** 当前用户密码 */
@property (nonatomic,weak) NSString *currentPassword;

@end

@implementation DBJSAndHPasswordVC
-(void)dbjSetupSubviews{
//    [super dbjSetupSubviews];

    //获取存储的密码
    _currentAccount = [DBJUserDefaultsTool objetForKey:CURRENTID];
    _currentPassword = [SSKeychain passwordForService:BUNDLEID account:_currentAccount];
}

- (IBAction)updatePasswordClick:(UIButton *)sender {
    
    //获取用户输入的密码
    NSString *oldPassword = _oldPaswordTextField.text;
    NSString *newPassword = _updateTextField.text;
    
    if(![_currentPassword isEqualToString:oldPassword]){
        
        [DBJTools dbjShowSVErrorTitle:@"旧密码与原密码不匹配"andTime:STANTIME];
        
    }else if(![NSString checkPassword:newPassword]){//判断新的登录密码是否符合正则
        
        [DBJTools dbjShowSVErrorTitle:@"请输入6-18位数字和字母组合的新密码" andTime:STANTIME];
        
    } else if([_currentPassword isEqualToString:newPassword]){
        
        [DBJTools dbjShowSVErrorTitle:@"旧密码与新密码不可以相同" andTime:STANTIME];
        
    }else{
        
        [SSKeychain setPassword:newPassword forService:BUNDLEID account:_currentAccount error:NULL];
        [DBJTools dbjShowSVSuccessTitle:@"密码修改成功" andTime:STANTIME];
        
    }
}


@end
